#include "hotkeyeditor.h"
#include "ui_hotkeyeditor.h"
#include "mainobject.h"

HotKeyEditor::HotKeyEditor(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::HotKeyEditor)
{
    m_ui->setupUi(this);
}

HotKeyEditor::~HotKeyEditor()
{
    delete m_ui;
}

void HotKeyEditor::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void HotKeyEditor::keyPressEvent(QKeyEvent *event){
    QKeySequence seq(event->modifiers(), event->key());
//    qDebug() << "Key pressed mod: " << event->modifiers() <<
//            " key: " << event->key() << "text: " << event->text() <<
//            "seq: " << seq.toString(QKeySequence::NativeText) <<
//            "seq: " << seq.toString(QKeySequence::PortableText);
    QString hotkey = seq.toString(QKeySequence::NativeText);
    hotkey.replace(", ", "");
    m_ui->hotkeyText->setText(hotkey);
    QDialog::keyPressEvent(event);
}

void HotKeyEditor::okClick(){
    MainObject::instance()->optionsWin->hotkeySet(m_ui->hotkeyText->text());
    hide();
}

void HotKeyEditor::cancelClick(){
    hide();
}

void HotKeyEditor::show(QString key){
    m_ui->hotkeyText->setText(key);
    QDialog::show();
}
